<?php
class BetChk_3d
{

    public $today;
    public $tbl;
    public $gametype;
    public $tblName;

    public function BetChk_3d( $today, $gametype = 1 )
    {
        global $g_gametype_3d;
        $this->today = $today;
        $this->gametype = $gametype;
        $this->tbl = $g_gametype_3d[$gametype]['en'];
        $this->tblName = $g_gametype_3d[$gametype]['ch'];
    }

    public function chkBetDate( )
    {
        global $conf;
        global $ui;
        global $show3D3S;
        if ( $this->gametype == 20 )
        {
            include_once( "class_5h/MyLotto_5h.php" );
            $MyLotto_3d = new MyLotto_5h( $this->gametype );
        }
        else
        {
            include_once( "class_3d/MyLotto_3d.php" );
            $MyLotto_3d = new MyLotto_3d( $this->gametype );
        }
        $reVal = false;
        switch ( $show3D3S )
        {
            case 0 :
                if ( $lotto_data = $MyLotto_3d->getLotto3DByDate( $this->today ) )
                {
                    $datehi = date( "Hi" );
                    if ( $conf->get( "stopbet_{$this->tbl}" ) <= $datehi )
                    {
                        $ui->showErrorPage( "目前非{$this->tblName}下单时段！", true );
                        $reVal = false;
                        exit();
                    }
                    else
                    {
                        if ( $datehi < $conf->get( "startbet_{$this->tbl}" ) )
                        {
                            $ui->showErrorPage( "目前非{$this->tblName}下单时段！", true );
                            $reVal = false;
                            exit();
                        }
                        else
                        {
                            if ( 0 < count( array_diff_assoc( array( 0 - 1, 0 - 1, 0 - 1 ), array( $lotto_data['n1'], $lotto_data['n2'], $lotto_data['n3'] ) ) ) )
                            {
                                $ui->showErrorPage( "{$this->tblName}::第".$lotto_data['round']."期<br />已截止下注！", true );
                                $reVal = false;
                                exit();
                            }
                            else
                            {
                                $reVal = $lotto_data;
                            }
                        }
                    }
                }
                else
                {
                    $ui->showErrorPage( "目前无{$this->tblName}可下注期数！", true );
                    $reVal = false;
                    exit();
                }
                break;
            case 1 :
            case 2 :
                if ( $lotto_data = $MyLotto_3d->getLotto3SByDateTime( ) )
                {
                    $reVal = $lotto_data;
                }
                else
                {
                    $ui->showErrorPage( "目前暂无{$this->tblName}可下注期数！", true );
                    $reVal = false;
                    exit();
                }
                break;
            default :
                exit( "error 3d3s" );
        }
        return $reVal;
    }

    public function chkBetDateJSON( )
    {
        global $conf;
        global $ui;
        global $show3D3S;
        if ( $this->gametype == 20 )
        {
            include_once( "class_5h/MyLotto_5h.php" );
            $MyLotto_5h = new MyLotto_5h( $this->gametype );
        }
        else
        {
            include_once( "class_3d/MyLotto_3d.php" );
            $MyLotto_3d = new MyLotto_3d( $this->gametype );
        }
        $reVal = false;
        switch ( $show3D3S )
        {
            case 0 :
                if ( $lotto_data = $MyLotto_3d->getLotto3DByDate( $this->today ) )
                {
                    $datehi = date( "Hi" );
                    if ( $conf->get( "stopbet_{$this->tbl}" ) <= $datehi )
                    {
                        header( "Cache-Control: no-cache, must-revalidate" );
                        header( "Content-Type: text/plain" );
                        echo "{\"msg\":\"2\"}";
                        $reVal = false;
                        exit();
                    }
                    else
                    {
                        if ( $datehi < $conf->get( "startbet_{$this->tbl}" ) )
                        {
                            header( "Cache-Control: no-cache, must-revalidate" );
                            header( "Content-Type: text/plain" );
                            echo "{\"msg\":\"2\"}";
                            $reVal = false;
                            exit();
                        }
                        else
                        {
                            $reVal = $lotto_data;
                        }
                    }
                }
                else
                {
                    header( "Cache-Control: no-cache, must-revalidate" );
                    header( "Content-Type: text/plain" );
                    echo "{\"msg\":\"2\"}";
                    $reVal = false;
                    exit();
                }
                break;
            case 1 :
            case 2 :
                if ( $lotto_data = $MyLotto_3d->getLotto3SByDateTime( ) )
                {
                    $reVal = $lotto_data;
                }
                else
                {
                    header( "Cache-Control: no-cache, must-revalidate" );
                    header( "Content-Type: text/plain" );
                    echo "{\"msg\":\"2\"}";
                    $reVal = false;
                    exit();
                }
                break;
            default :
                exit( "error 3d3s" );
        }
        return $reVal;
    }

}

?>